package gov.pbc.gx.nn.pz.menu;

import java.util.UUID;

import org.apache.commons.lang.StringUtils;
import org.hibernate.Session;
import org.springframework.stereotype.Component;

import com.bstek.bdf2.core.CoreHibernateDao;
import com.bstek.bdf2.core.business.IMenuGenerator;
import com.bstek.bdf2.core.business.IUser;
import com.bstek.bdf2.core.context.ContextHolder;
import com.bstek.bdf2.core.model.Url;

/**
 * 
 * @author jack.zhao 该类主要生成系统菜单！
 */
@Component
public class SystemMenu extends CoreHibernateDao implements IMenuGenerator {

	public void generate(Session session, String rootId) {
		
		Url secondUrl = this.createUrl("凭证打印", "url(>skin>common/icons.gif) -60px -40px", rootId, 1, null);
		session.save(secondUrl);
		Url childUrl = this.createUrl("城市管理员", "url(>skin>common/icons.gif) -140px -100px", secondUrl.getId(), 1, "gov.pbc.gx.nn.pz.view.UserAdmin.d");
		session.save(childUrl);
		childUrl = this.createUrl("业务人员维护", "url(>skin>common/icons.gif) -160px -100px", secondUrl.getId(), 2, "gov.pbc.gx.nn.pz.view.UserYw.d");
		session.save(childUrl);
		childUrl = this.createUrl("账号户名维护", "url(>skin>common/icons.gif) -160px -100px", secondUrl.getId(), 3, "gov.pbc.gx.nn.pz.view.Account.d");
		session.save(childUrl);

		childUrl = this.createUrl("转账凭证", "url(>skin>common/icons.gif) -40px -120px", secondUrl.getId(), 4, "gov.pbc.gx.nn.pz.view.zzpz1.d");
		session.save(childUrl);
		childUrl = this.createUrl("表外凭证", "url(>skin>common/icons.gif) -40px -120px", secondUrl.getId(), 5, "gov.pbc.gx.nn.pz.view.bwpz.d");
		session.save(childUrl);
		childUrl = this.createUrl("特种存款业务调整申请单凭证打印", "url(>skin>common/icons.gif) -40px -120px", secondUrl.getId(), 6, "gov.pbc.gx.nn.pz.view.HcTzckywTzsqd.d");
		session.save(childUrl);
		childUrl = this.createUrl("同城票据交换差额清算凭证", "url(>skin>common/icons.gif) -40px -120px", secondUrl.getId(), 7, "gov.pbc.gx.nn.pz.view.tcpjjhceqs.d");
		session.save(childUrl);
		childUrl = this.createUrl("现金凭证", "url(>skin>common/icons.gif) -40px -120px", secondUrl.getId(), 8, "gov.pbc.gx.nn.pz.view.xjpz.d");
		session.save(childUrl);
		childUrl = this.createUrl("再贷款业务调整打印", "url(>skin>common/icons.gif) -40px -120px", secondUrl.getId(), 9, "gov.pbc.gx.nn.pz.view.zdkywtz.d");
		session.save(childUrl);
		childUrl = this.createUrl("账户管理信息表", "url(>skin>common/icons.gif) -40px -120px", secondUrl.getId(), 10, "gov.pbc.gx.nn.pz.view.Zhglxx.d");
		session.save(childUrl);
		childUrl = this.createUrl("账务调整凭证", "url(>skin>common/icons.gif) -40px -120px", secondUrl.getId(), 11, "gov.pbc.gx.nn.pz.view.zwtzpz.d");
		session.save(childUrl);
		childUrl = this.createUrl("重要空白凭证业务处理单", "url(>skin>common/icons.gif) -40px -120px", secondUrl.getId(), 12, "gov.pbc.gx.nn.pz.view.Zykbpzyw.d");
		session.save(childUrl);

	}

	private Url createUrl(String name, String icon, String parentId, int order, String targetUrl) {
		IUser user = ContextHolder.getLoginUser();
		String companyId = user.getCompanyId();
		if (StringUtils.isNotEmpty(getFixedCompanyId())) {
			companyId = getFixedCompanyId();
		}
		Url url = new Url();
		url.setId(UUID.randomUUID().toString());
		url.setName(name);
		url.setIcon(icon);
		url.setUrl(targetUrl);
		url.setParentId(parentId);
		url.setCompanyId(companyId);
		url.setForNavigation(true);
		url.setOrder(order);
		return url;
	}
}
